/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans.ejb;

import entities.Fantasyleague;
import entities.Fantasyteam;
import entities.Fantasyuser;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author The Lunatics
 */
@Stateless
public class FantasyleagueFacade extends AbstractFacade<Fantasyleague> {

    @PersistenceContext(unitName = "Touchdown308PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public FantasyleagueFacade() {
        super(Fantasyleague.class);
    }

    public List<Fantasyleague> getUsersLegues(Fantasyuser id) {
        Query createQuery = getEntityManager().createQuery("select f.leagueId from Fantasyteam f where f.userId = :userId");
        createQuery.setParameter("userId", id);

        List<Fantasyleague> l = createQuery.getResultList();

        return l;
    }
     
    
    public void createLeague(Fantasyleague league) {
        em.persist(league);
    }
}
